package com.muma.util;

import lombok.SneakyThrows;

import java.io.*;

public  class StreamConnector extends Thread{
        InputStream is;
        OutputStream os;
        public StreamConnector(InputStream is, OutputStream os)
        {
            this.is = is;
            this.os = os;
        }
        @SneakyThrows
        public void run()
        {
            BufferedReader isr = null;
            BufferedWriter osw = null;
                isr = new BufferedReader(new InputStreamReader(is));
                osw = new BufferedWriter(new OutputStreamWriter(os));
                char buffer[] = new char[8192];
                int lenRead;
                while( (lenRead = isr.read(buffer, 0, buffer.length)) > 0)
                {
                    osw.write(buffer, 0, lenRead);
                    osw.flush();
                }

                if(isr != null) isr.close();
                if(osw != null) osw.close();

        }
}
